const mongoose = require('mongoose')

const HOST = 'mongodb://localhost:27017/mydb'
const OPTS = {useNewUrlParser: true, useUnifiedTopology: true}

// 连接mongodb服务器
mongoose.connect(HOST, OPTS)

// 创建Schema
const schema = new mongoose.Schema({
  username: {
    type: String,
    required: true,
    minlength: 2,
    // 唯一
    unique: true
  },
  password: String,
  sex: {
    type: String,
    // 枚举
    enum: ['男', '女'],
    default: '男'
  },
  hobbies: [String],
  intro: String
})

// 操作的模型
const model = mongoose.model('User', schema)

module.exports = model
